package ssm.blog.controller.onstage;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import ssm.blog.entity.Blog;
import ssm.blog.service.BlogService;
import ssm.blog.util.ResponseUtil;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: lyon
 * @description: 前台博客控制层
 * @author: Lyon
 * @create: 2018-05-31 21:12
 **/
@Controller
@RequestMapping("/onstage/blog")
public class BlogController {
    @Resource
    BlogService blogService;
    @RequestMapping("/like")
    String like(Integer id, HttpServletResponse response) throws Exception {
        Blog blog=blogService.selectById(id);
        blog.setLikenum(blog.getLikenum()+1);
        int resultRows=blogService.updateById(blog);
        JSONObject result=new JSONObject();
        if(resultRows>0){
            result.put("success",true);
        }else{
            result.put("success",false);
        }
        ResponseUtil.write(response,result);
        return null;
    }
}
